package com.example.day02;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.day02.v.V_view;

import org.w3c.dom.Text;

import java.util.ArrayList;

public class Recy_Adapter extends RecyclerView.Adapter<Recy_Adapter.ViewHolder> {
  Context context;
  ArrayList<GetBean.ResultsBean>getresu;

    public Recy_Adapter(Context context, ArrayList<GetBean.ResultsBean> getresu) {
        this.context = context;
        this.getresu = getresu;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View inflate = LayoutInflater.from(context).inflate(R.layout.item, parent, false);
        return new ViewHolder(inflate);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, final int position) {
        GetBean.ResultsBean bean = getresu.get(position);
        holder.text.setText(bean.getDesc());
        Glide.with(context).load(bean.getUrl()).into(holder.img);
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                oncreate.oncreate(position);
            }
        });

    }

    @Override
    public int getItemCount() {
        return getresu.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        ImageView img;
        TextView text;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            img=itemView.findViewById(R.id.img);
            text=itemView.findViewById(R.id.text);
        }
    }
    Oncreate oncreate;

    public void setOncreate(Oncreate oncreate) {
        this.oncreate = oncreate;
    }

    interface   Oncreate{
        void oncreate(int position);
    }
}
